package com.sky.controller.user;


import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.IAddressBookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 地址簿 前端控制器
 * </p>
 *
 * @author xieminghui
 * @since 2023-11-28
 */
@RestController
@RequestMapping("/user/addressBook")
public class AddressBookController {
    @Resource
    private IAddressBookService iAddressBookService;
    /**
     * 1查询当前用户所有地址
     * @author: XieMingHui
     * @param: []
     * @return: com.sky.result.Result<java.util.List<com.sky.entity.AddressBook>>
     **/
    @GetMapping("/list")
    public Result<List<AddressBook>> findList(){
        return iAddressBookService.findList();
    }
    /**
     * 2新增地址
     * @author: XieMingHui
     * @param: []
     * @return: 返回成功响应
     **/
    @PostMapping
    public Result<String> saveAddress(@RequestBody AddressBook addressBook){
        return iAddressBookService.saveAddress(addressBook);
    }
    /**
     * 3查询用户默认地址
     * @author: XieMingHui
     * @param: []
     * @return: 返回地址对象
     **/
    @GetMapping("/default")
    public Result<AddressBook> findOneAddress(){
        Long id = null;
        return iAddressBookService.findOneAddress(id);
    }
    /**
     * 4根据地址id查询地址
     * @author: XieMingHui
     * @param: [路径占位符id]
     * @return: 返回地址对象
     **/
    @GetMapping("/{id}")
    public Result<AddressBook> findList(@PathVariable Long id){
        return iAddressBookService.findOneAddress(id);
    }
    /**
     * 5根据id修改地址
     * @author: XieMingHui
     * @param: [地址对象]
     * @return: 返回成功响应
     **/
    @PutMapping
    public Result<String> updateAddress(@RequestBody AddressBook addressBook){
        return iAddressBookService.updateAddress(addressBook);
    }
    /**
     * 6根据地址id删除地址
     * @author: XieMingHui
     * @param: [地址id]
     * @return: 返回成功响应
     **/
    @DeleteMapping
    public Result<String> deleteAddress(@RequestParam Long id){
        return iAddressBookService.deleteAddress(id);
    }
    /**
     * 7设置默认地址
     * @author: XieMingHui
     * @param: []
     * @return: 返回成功响应
     **/
    @PutMapping("/default")
    public Result<String> updateDefaultAddress(@RequestBody AddressBook addressBook){
        return iAddressBookService.updateDefaultAddress(addressBook);
    }
}
